import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import 'package:mtf/app/modules/mine_module/mine_controller.dart';
import 'package:mtf/app/theme/app_colors.dart';
import 'package:mtf/app/utils/cache/AppCahche.dart';
import 'package:mtf/app/widget/ClickableText.dart';
import 'package:mtf/app/widget/HcIconText.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import '../../../R.dart';
import '../../widget/MySeparator.dart';
/**
 * GetX Template Generator - fb.com/htngu.99
 * */

class minePage extends StatelessWidget {
  var controller = Get.put(mineController());

  @override
  Widget build(BuildContext context) {
    controller.refreshData();
    return Scaffold(
      backgroundColor: c_f3f5f7,
      body: Stack(
        children: [
          Container(
              width: double.infinity,
              height: 320,
              child: Image.asset(R.assetsImgBgMineTop, fit: BoxFit.fill)),
          RefreshConfiguration(
            headerBuilder: () => MaterialClassicHeader(),
            child: SmartRefresher(
              onRefresh: () {
                controller.refreshData();
              },
              controller: controller.refreshController,
              child: Obx(() {
                return SizedBox(
                  width: double.infinity,
                  child: Column(
                    children: [
                      Container(
                        margin: EdgeInsets.only(left: 24, top: 90),
                        child: Row(
                          children: [
                            InkWell(
                              onTap: () {
                                controller.clickSetting();
                              },
                              child: ClipOval(
                                  child: Image.network(
                                controller.user.value.headUrl ??
                                    "https://via.placeholder.com/52x52",
                                height: 52,
                                width: 52,
                                fit: BoxFit.fill,
                              )),
                            ),
                            SizedBox(width: 10),
                            Obx(() {
                              return Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Text(
                                    controller.user.value.nikname ?? "请登录",
                                    style: TextStyle(
                                        fontSize: 18,
                                        fontWeight: FontWeight.bold,
                                        color: c_333333),
                                  ),
                                  SizedBox(height: 5),
                                  Visibility(
                                    visible: AppCache.isLogin(),
                                    child: Row(
                                      children: [
                                        Image.asset(
                                            controller.user.value.authStatus ==
                                                    2
                                                ? R.assetsImgIcAuthentication_jpg
                                                : R.assetsImgIcDisauthentication,
                                            height: 18,
                                            width: 56),
                                        SizedBox(width: 5),
                                        Text(
                                          "ID:${controller.user.value.id.toString()}",
                                          style: TextStyle(
                                              fontSize: 12, color: c_535d82),
                                        )
                                      ],
                                    ),
                                  )
                                ],
                              );
                            })
                          ],
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.only(left: 20, right: 20, top: 35),
                        padding:
                            EdgeInsets.symmetric(horizontal: 15, vertical: 8),
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.only(
                                topRight: Radius.circular(10),
                                topLeft: Radius.circular(10)),
                            gradient: LinearGradient(
                                begin: Alignment.topCenter, //渐变开始于上面的中间开始
                                end: Alignment.bottomCenter,
                                colors: [c_f33126, c_ff5a4c])),
                        child: Flex(
                          direction: Axis.horizontal,
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text(
                                  "我的资产(USD)",
                                  style: TextStyle(
                                      fontSize: 13, color: Colors.white),
                                ),
                                Obx(() {
                                  return Text(
                                    controller.user.value.mt5Balance ?? "0.00",
                                    style: TextStyle(
                                        fontSize: 18,
                                        color: Colors.white,
                                        fontWeight: FontWeight.bold),
                                  );
                                }),
                              ],
                            ),
                            Container(
                                padding: EdgeInsets.symmetric(
                                    vertical: 7, horizontal: 19),
                                decoration: BoxDecoration(
                                    borderRadius: BorderRadius.circular(16),
                                    gradient: LinearGradient(
                                        colors: [c_ffecd7, c_ffbca6])),
                                child: ClickableText(
                                    text: "查看",
                                    style: TextStyle(
                                        color: c_c84002, fontSize: 13),
                                    onClick: () {
                                      controller.clickProperty();
                                    }))
                          ],
                        ),
                      ),
                      Divider(height: 1),
                      Container(
                        width: double.infinity,
                        padding:
                            EdgeInsets.symmetric(vertical: 18, horizontal: 10),
                        decoration: BoxDecoration(
                            color: c_f3f5f7,
                            borderRadius: BorderRadius.only(
                                topLeft: Radius.circular(16),
                                topRight: Radius.circular(16))),
                        child: Column(
                          children: [
                            Obx(() {
                              return Offstage(
                                offstage:
                                    controller.user.value.getCurrentStep() >= 4,
                                child: Container(
                                  width: double.infinity,
                                  margin: EdgeInsets.only(bottom: 10),
                                  padding: EdgeInsets.symmetric(
                                      vertical: 15, horizontal: 10),
                                  decoration: BoxDecoration(
                                      color: Colors.white,
                                      borderRadius: BorderRadius.circular(10)),
                                  child: Obx(() {
                                    return Column(
                                      children: [
                                        Offstage(
                                          offstage:
                                              !controller.isShowTime.value,
                                          child: Text.rich(TextSpan(children: [
                                            TextSpan(
                                                text: "新客限时领",
                                                style:
                                                    TextStyle(color: c_333333)),
                                            WidgetSpan(
                                                child: SizedBox(width: 5)),
                                            TextSpan(
                                                text:
                                                    " ${controller.day.value} ",
                                                style: TextStyle(
                                                    color: c_f12f38,
                                                    backgroundColor: c_ffcece,
                                                    fontSize: 15,
                                                    fontWeight:
                                                        FontWeight.bold)),
                                            WidgetSpan(
                                                child: SizedBox(width: 5)),
                                            TextSpan(text: "天")
                                          ])),
                                        ),
                                        SizedBox(height: 10),
                                        Text(
                                          controller.content.value,
                                          style: TextStyle(
                                              color: c_f12f38,
                                              fontSize: 15,
                                              fontWeight: FontWeight.bold),
                                        ),
                                        Container(
                                          margin: EdgeInsets.only(top: 10),
                                          padding: EdgeInsets.symmetric(
                                              vertical: 5, horizontal: 10),
                                          child: InkWell(
                                            onTap: () {
                                              controller.clickActivity();
                                            },
                                            child: Text(
                                              "马上激活",
                                              style: TextStyle(
                                                  color: Colors.white),
                                            ),
                                          ),
                                          decoration: BoxDecoration(
                                              color: c_f12f38,
                                              borderRadius:
                                                  BorderRadius.circular(14)),
                                        ),
                                        SizedBox(height: 10),
                                        Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.spaceAround,
                                          children: [
                                            Column(
                                              children: [
                                                Image.asset(
                                                  controller.user.value
                                                              .getCurrentStep() <=
                                                          0
                                                      ? R.assetsImgIcSfzOff
                                                      : R.assetsImgIcSfzOn,
                                                  width: 40,
                                                  height: 40,
                                                ),
                                                Text("身份认证")
                                              ],
                                            ),
                                            Container(
                                              child: SizedBox(
                                                  width: 20,
                                                  child: MySeparator(
                                                      color: Colors.grey)),
                                              margin:
                                                  EdgeInsets.only(bottom: 10),
                                            ),
                                            Column(
                                              children: [
                                                Image.asset(
                                                  controller.user.value
                                                              .getCurrentStep() <=
                                                          1
                                                      ? R.assetsImgIcInfoOff
                                                      : R.assetsImgIcInfoOn,
                                                  width: 40,
                                                  height: 40,
                                                ),
                                                Text("添加银行卡")
                                              ],
                                            ),
                                            Container(
                                              child: SizedBox(
                                                  width: 20,
                                                  child: MySeparator(
                                                      color: Colors.grey)),
                                              margin:
                                                  EdgeInsets.only(bottom: 10),
                                            ),
                                            Column(
                                              children: [
                                                Image.asset(
                                                  controller.user.value
                                                              .getCurrentStep() <=
                                                          2
                                                      ? R.assetsImgIcAskOff
                                                      : R.assetsImgIcAskOn,
                                                  width: 40,
                                                  height: 40,
                                                ),
                                                Text("调查问卷")
                                              ],
                                            ),
                                            Container(
                                              child: SizedBox(
                                                  width: 20,
                                                  child: MySeparator(
                                                      color: Colors.grey)),
                                              margin:
                                                  EdgeInsets.only(bottom: 10),
                                            ),
                                            Column(
                                              children: [
                                                Image.asset(
                                                  controller.user.value
                                                              .getCurrentStep() <=
                                                          3
                                                      ? R.assetsImgIcRechargeOff
                                                      : R.assetsImgIcRechargeOn,
                                                  width: 40,
                                                  height: 40,
                                                ),
                                                Text("存款激活")
                                              ],
                                            ),
                                          ],
                                        )
                                      ],
                                    );
                                  }),
                                ),
                              );
                            }),
                            InkWell(
                              onTap: () {
                                controller.clickAuth();
                              },
                              child: Container(
                                padding: EdgeInsets.symmetric(
                                    vertical: 14, horizontal: 10),
                                decoration: BoxDecoration(
                                    color: Colors.white,
                                    borderRadius: BorderRadius.only(
                                        topRight: Radius.circular(16),
                                        topLeft: Radius.circular(16))),
                                child: Flex(
                                  direction: Axis.horizontal,
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    HcIconText(
                                      icon: Image.asset(
                                        R.assetsImgIcAuth,
                                        width: 18,
                                        height: 18,
                                      ),
                                      label: Text(
                                        "实名认证",
                                        style: TextStyle(
                                            color: c_333333, fontSize: 15),
                                      ),
                                    ),
                                    HcIconText(
                                      reverse: true,
                                      icon: SvgPicture.asset(
                                        R.assetsImgIcSvgRight,
                                        width: 16,
                                        height: 16,
                                      ),
                                      label: Obx(() {
                                        return Text(
                                          controller.user.value.authStatusStr(),
                                          style: TextStyle(
                                              color: c_f12f38, fontSize: 15),
                                        );
                                      }),
                                    )
                                  ],
                                ),
                              ),
                            ),
                            InkWell(
                              onTap: () {},
                              child: Container(
                                padding: EdgeInsets.symmetric(
                                    vertical: 14, horizontal: 10),
                                decoration: BoxDecoration(
                                  color: Colors.white,
                                ),
                                child: InkWell(
                                  onTap: () {
                                    controller.clickTransactionRecode();
                                  },
                                  child: Flex(
                                    direction: Axis.horizontal,
                                    mainAxisAlignment:
                                        MainAxisAlignment.spaceBetween,
                                    children: [
                                      HcIconText(
                                        icon: Image.asset(
                                          R.assetsImgIcChang,
                                          width: 18,
                                          height: 18,
                                        ),
                                        label: Text(
                                          "交易记录",
                                          style: TextStyle(
                                              color: c_333333, fontSize: 15),
                                        ),
                                      ),
                                      HcIconText(
                                        reverse: true,
                                        icon: SvgPicture.asset(
                                          R.assetsImgIcSvgRight,
                                          width: 16,
                                          height: 16,
                                        ),
                                        label: Text(
                                          "",
                                          style: TextStyle(
                                              color: c_f12f38, fontSize: 15),
                                        ),
                                      )
                                    ],
                                  ),
                                ),
                              ),
                            ),
                            InkWell(
                              onTap: () {
                                controller.clickSetting();
                              },
                              child: Container(
                                padding: EdgeInsets.symmetric(
                                    vertical: 14, horizontal: 10),
                                decoration: BoxDecoration(
                                    color: Colors.white,
                                    borderRadius: BorderRadius.only(
                                        bottomLeft: Radius.circular(16),
                                        bottomRight: Radius.circular(16))),
                                child: Flex(
                                  direction: Axis.horizontal,
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    HcIconText(
                                      icon: Image.asset(
                                        R.assetsImgIcSetting,
                                        width: 18,
                                        height: 18,
                                      ),
                                      label: Text(
                                        "我的设置",
                                        style: TextStyle(
                                            color: c_333333, fontSize: 15),
                                      ),
                                    ),
                                    HcIconText(
                                      reverse: true,
                                      icon: SvgPicture.asset(
                                        R.assetsImgIcSvgRight,
                                        width: 16,
                                        height: 16,
                                      ),
                                      label: Text(
                                        "",
                                        style: TextStyle(
                                            color: c_f12f38, fontSize: 15),
                                      ),
                                    )
                                  ],
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                );
              }),
            ),
          ),
          Align(
            alignment: Alignment.bottomRight,
            child: Container(
              width: 55,
              height: 70,
              margin: EdgeInsets.only(right: 20),
              child: InkWell(
                onTap: (){
                  controller.clickKeFu();
                },
                child: Column(
                  children: [
                    Image.asset(
                      R.assetsImgIcKefu,
                      width: 45,
                      height: 45,
                    ),
                    Text("客服")
                  ],
                ),
              ),
            ),
          )
        ],
      ),
    );
  }
}
